//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pt;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.PtBespeakDao;
import com.aidong.dao.wills.PtCoachCodeDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.model.wills.ContractInfo;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"ptBespeakQuery"})
public class PtBespeakQueryController extends BaseController {
    @Resource
    PtBespeakDao ptBespeakDao;
    @Resource
    PtContractDao ptContractDao;
    @Resource
    PtCoachCodeDao ptCoachCodeDao;
    @Resource
    MemberInfoDao memberInfoDao;

    public PtBespeakQueryController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("pt/bespeakquery/list")).addObject("bespeakStatus", this.getTypeList("bespeakStatus")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "coachCode",required = false) String coachCode, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "b.shopCode", shopCode);
        cd.eq("b.memberCode", memberCode);
        cd.eq("b.coachCode", coachCode);
        cd.eq("b.status", status);
        if("2".equals(dateType)) {
            if(!this.chkNull(dateFrom)) {
                cd.ge("b.clearTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("b.clearTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
            }
        } else {
            if(!this.chkNull(dateFrom)) {
                cd.ge("b.classTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("b.classTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
            }
        }

        this.ptBespeakDao.queryPageList2(pg, cd);
        ModelAndView mv = new ModelAndView("pt/bespeakquery/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "coachCode",required = false) String coachCode, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "b.shopCode", shopCode);
            cd.eq("b.memberCode", memberCode);
            cd.eq("b.coachCode", coachCode);
            cd.eq("b.status", status);
            if("2".equals(dateType)) {
                if(!this.chkNull(dateFrom)) {
                    cd.ge("b.clearTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
                }

                if(!this.chkNull(dateTo)) {
                    cd.le("b.clearTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
                }
            } else {
                if(!this.chkNull(dateFrom)) {
                    cd.ge("b.classTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
                }

                if(!this.chkNull(dateTo)) {
                    cd.le("b.classTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
                }
            }

            this.ptBespeakDao.queryPageList2(e, cd);
            ExportXls xls = new ExportXls(response, "私教预约核销流水", "私教预约核销流水");
            xls.addHead(new String[]{"门店编号", "门店名称", "合同号", "会员号", "卡号", "会员姓名", "课程编号", "课程名称", "教练编号", "教练姓名", "预约上课时间", "核销时间", "预约状态", "课时单价", "购买课时", "购买金额", "销售教练编号", "销售教练姓名", "购买日期", "结束日期", "操作员", "流水号"});
            xls.setWidth(new int[]{10, 10, 15, 20, 10, 10, 10, 30, 10, 10, 20, 12, 10, 10, 10, 10, 12, 12, 20, 12, 20, 10});
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                ContractInfo contract = (ContractInfo)i$.next();
                xls.addRow(new Object[]{contract.getShopCode(), this.cache.getValue("shopName", contract.getShopCode()), contract.getContractCode(), contract.getMemberCode(), contract.getCardCode(), contract.getMemberName(), contract.getPtCode(), this.cache.getValue("ptItemName", contract.getPtCode()), contract.getCoachCode(), this.cache.getValue("ptCoachName", contract.getCoachCode()), sdf2.format(contract.getClassTime()), contract.getClearTime() == null?"":sdf.format(contract.getClearTime()), this.cache.getValue("bespeakStatus", String.valueOf(contract.getStatus())), contract.getQuantity().intValue() != 0?Double.valueOf((double)Math.round(contract.getFactPrice().doubleValue() * 100.0D / (double)contract.getQuantity().intValue()) / 100.0D):null, contract.getQuantity(), contract.getFactPrice(), this.nvl(contract.getSalesCode()), this.nvl(this.cache.getValue("salesName", contract.getSalesCode())), sdf2.format(contract.getSaleDate()), sdf.format(contract.getEndTime()), this.nvl(contract.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", contract.getCreateUser())), contract.getAutoId()});
            }

            xls.close();
            this.addUserLog("导出私教预约核销流水", e.getResultList().size() + "条记录");
        } catch (Exception var16) {
            this.log.error("import", var16);
        }

        return null;
    }
}
